<?php


namespace app\blog\model;


use think\Model;

/**
 * 访客统计model
 * Class VisitorModel
 * @package app\blog\model
 */
class VisitorModel extends Model
{
    protected $name = "visitor";

    public function numOfWeek()
    {
        $data = [];
        $day = 6;
        while ($day >= -1) {
            $time = ($day > -1) ? date('Y-m-d 00:00:00', strtotime('- ' . $day . ' day'))
                : date('Y-m-d H:i:s');
            $date = date('m-d', strtotime('- ' . ($day + 1) . ' day'));
            $num = $this->where('last_time', '<', $time)->count('id');

            $data['date'][] = $date;
            $data['num'][] = $num;

            $day -= 1;
        }
        return $data;
    }

    /**
     * 访问量统计
     * @return array
     */
    public function stt()
    {
        $ipNum = $this->count('id');
        $pvNum = $this->value('sum(times)');
        return [$ipNum, $pvNum];
    }
}